
"""
    check your passwd level

    FORMAT：
        check_passwd('passwd')

    RETURN LEVEL, SHORTCOMING

    ------------------------------------------------

    Cryptographic complexity standard：
        1.Length greater than or equal to 8
        2.It is composed of more than three kinds of characters: number, uppercase, lowercase and special characters
        3.No repetition of three or more characters

"""

import re
# 密码的复杂度验证


def check_passwd(passwd):
    # 初始化计分
    count = 2
    num = 0
    er_str = ""

    # 检查长度
    # 长度合格，分数+1
    if len(passwd) >= 8:
        count = count + 1
    else:
        er_str = er_str + '▪长度小于8 '

    # 检查符号
    # 包含小写
    if re.search('[a-z]', passwd):
        num = num + 1
    # 包含大写
    if re.search('[A-Z]', passwd):
        num = num + 1
    # 包含数字
    if re.search('[0-9]', passwd):
        num = num + 1
    # 包含未知字符
    if re.search('[^0-9]|[^A-Z]|[^a-z]', passwd):
        num = num + 1
    # 不合格
    if num < 3:
        er_str = er_str + '▪密码没有由3种以上的字符组成 '
    # 合格！分数+1
    else:
        count = count + 1

    # 检查重复
    flag = 0
    for i in range(0, len(passwd) - 2):
        # 代码重复过多
        if passwd.count(passwd[i:i + 3]) > 1:
            flag = 1
    # 密码不重复，合格，分数+1
    if flag == 0:
        count = count + 1
    # 不合格
    else:
        er_str = er_str + '▪密码有长度超过或等于3的子串重复 '

    return count, er_str
